package com.wenqiner.requesttool.core.thread;


/**
 * @author rhf
 * @date 2023-03-28
 **/
public class ThreadTemplate {

    public Thread getCustomerThread(Runnable runnable, Integer priority) {
        ThreadGroup tg = Thread.currentThread().getThreadGroup();
        for (ThreadGroup tgn = tg;
             tgn != null;
             tg = tgn, tgn = tg.getParent()) {
            Thread thread = new CustomerThread(tg, runnable);
            thread.setPriority(priority);
            thread.setDaemon(true);
            return thread;
        }
        return null;
    }

    private static class CustomerThread extends Thread {
        CustomerThread(ThreadGroup g, Runnable runnable) {
            super(g, runnable, "thread-customer");
        }
        CustomerThread(ThreadGroup g, Runnable runnable, String threadNamePrefix) {
            super(g, runnable, threadNamePrefix);
        }

    }
}
